package com.csproj.siiat.base.common.service;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.LinkedList;
import java.util.concurrent.ConcurrentLinkedQueue;

import com.csproj.siiat.base.common.util.TLMessage.TLMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.csproj.siiat.config.ApplicationProperties;
import com.csproj.siiat.base.common.util.TCPServer;

/**
 * Created by tyshi on 2018/9/26.
 * 
 * this will be main thread to receiving TCP heartbeat from remote
 * then validate and parse the received digits into queque
 * 
 */

@Service
public class TCPReceiverService {

    private final Logger logger = LoggerFactory.getLogger(TCPReceiverService.class);

    // 24 * 60 * 2 * 100 = 288000
    public static ConcurrentLinkedQueue MQ = new ConcurrentLinkedQueue<TLMessage>();

    private ApplicationProperties applicationProperties;


    private int port = 8888;
   
    private static boolean running = true;
    
    private ServerSocket server = null;

    public TCPReceiverService(ApplicationProperties applicationProperties) {
    	this.applicationProperties = applicationProperties;
    	TCPServer ts = new TCPServer(applicationProperties.getTcpReceiverPort());
    	ts.start();
    	logger.info("TCP server started");

    }
}
